# -*- coding: utf-8 -*-
# @Time:2021/04/18 15:29
# @Author:Cindy
from selenium.webdriver.common.by import By

from pages.add_department_page import AddDepartment
from pages.add_member_page import AddMember
from pages.base_page import BasePage


class Contact(BasePage):

    def get_memberlist(self):
        """
        返回成员列表
        :return:
        """
        datas = self.driver.find_elements(By.CSS_SELECTOR,
                                          "#member_list>tr>.member_colRight_memberTable_td:nth-child(2)")
        namelist = []
        # for data in datas:
        #     namelist.append(data.text)
        namelist = [data.text for data in datas]
        print(namelist)
        return namelist

    def goto_addmember(self):
        """
        点击“添加成员”按钮，返回添加成员实例对象
        :return:
        """
        self.driver.find_element(By.CSS_SELECTOR, ".ww_operationBar>a:nth-child(2)").click()
        return AddMember(self.driver)

    def goto_add_department(self):
        """
        点击“添加部门”按钮，跳出添加部门弹窗，确定或取消后返回通讯录界面
        :return:
        """
        self.driver.find_element(By.CSS_SELECTOR, ".member_colLeft_top a:nth-child(2)").click()
        self.driver.find_element(By.CSS_SELECTOR, ".member_colLeft .vakata-context .js_create_party").click()
        return AddDepartment(self.driver)

    def get_departlist(self):
        """
        返回部门列表
        :return:
        """
        datas = self.driver.find_elements(By.CSS_SELECTOR, ".jstree-anchor")

        namelist = []
        # for data in datas:
        #     namelist.append(data.text)
        dapartlist = [data.text for data in datas]
        print(dapartlist)
        return dapartlist